var str = "";
$.ajax({
    url:"/RuanJianKeShe/getAllCoursesInfo",
    type:"post",
    data:{
        "msg":"getAllCoursesInfo",
    },
    dataType:"json",
    success:function(data){
        showAllCourses(data.allCoursesList,data.courseAndSum);
    },
    error:function(){
        alert("fail");
    }
})
function showAllCourses(data,sum) {
    var str = "";
    for (var i = 0; i < data.length; i++) {
        for (var j = 0; j < sum.length; j++){
            if (data[i].cno == sum[j].cno){
                var count = data[i].capacity-sum[j].sum;
            }
        }
        //拼接表格的行和列
        str = "<tr><td>" + data[i].cno +  "</td><td>" +data[i].cname + "</td><td>" +
            data[i].credit + "</td><td>" + count +"</td><td>" + data[i].capacity +
            "</td><td>" + data[i].address +  "</td><td>" +
            "<button onclick=\"updateHandle(this.value)\" id="+ data[i].cno +" value="+data[i].cno+">修改</button>" +
            "</td><td>" + "<button onclick=\"deleteHandle("+data[i].cno+")\">删除</button>" +"</td><td></td></tr>";
        //追加到table中
        $("#tab").append(str);
    }
}
deleteHandle = function (data) {
    $.ajax({
        url:"/RuanJianKeShe/delCourseInfo",
        type:"post",
        data:{
            "msg":"delCourseInfo",
            "cno":data
        },
        dataType:"json",
        success:function(success){
            alert(success)
        },
        error:function(){
            alert("fail");
        }
    })
    window.location.reload();
}
updateHandle = function (value) {
    window.location.href="../../../html/manager/update/updateCourseInfo.html?index="+value;
}
add = function () {
    window.location.href="../../../html/manager/add/addCourseInfo.html"
}